#include "ProviderExtend.h"

#include "core/AppSignals.h"

ProviderExtend::ProviderExtend()
    : PropertyProvider()
{
}

void ProviderExtend::initEditor(
    QtTreePropertyBrowser* editor,
    shared_ptr<BaseElement> entity
)
{
    entity_ = dynamic_pointer_cast<uml::Extend>(entity);
    propertyToId.clear();
    PropertyProvider::initEditor(editor, entity);

    addProperty("name", "name", entity_->name());
    addProperty("qualifiedName", "qualifiedName", entity_->qualifiedName());
    QStringList visibilityNames;
    visibilityNames.append("public");
    visibilityNames.append("private");
    visibilityNames.append("protected");
    visibilityNames.append("package");
    addProperty("visibility", "visibility", static_cast<int>(entity_->visibility()), visibilityNames);

}

void ProviderExtend::valueChanged(QtProperty* property, bool value)
{
    QString id = propertyToId[property];
    
}

void ProviderExtend::valueChanged(QtProperty* property, double value)
{
    QString id = propertyToId[property];
    
}

void ProviderExtend::valueChanged(QtProperty* property, int value)
{
    QString id = propertyToId[property];
    if (id == "visibility") {
        entity_->setVisibility(static_cast<VisibilityKind>(value));
        emit appSignals->onElementChanged(this, entity_);
    }
}

void ProviderExtend::valueChanged(QtProperty* property, QString value)
{
    QString id = propertyToId[property];
    if (id == "name") {
        entity_->setName(value);
        emit appSignals->onElementRenamed(this, entity_);
    } else if (id == "qualifiedName") {
        entity_->setQualifiedName(value);
        emit appSignals->onElementChanged(this, entity_);
    }
}
